package com.itcast.jdbc.test03;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JdbcTest04 {

    public static void main(String[] args) throws SQLException {
        //将id 为4的数据删除
        int i = deleteBrandById(4);

    }

    private static int deleteBrandById(int id) throws SQLException {
        //获取连接
        Connection connection = DatasourceUtils.getConnection();

        //编写sql
        String sql="delete from  tb_brand  where id=? ";
        //绑定preparedStatement的参数
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        preparedStatement.setInt(1,id);

        //执行
        int i = preparedStatement.executeUpdate();

        //关闭资源
        preparedStatement.close();
        //归还连接给连接池
        connection.close();

        return i;
    }




}

